package com.xxxx.server.controller;


import com.xxxx.server.pojo.Menu;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IMenuRoleService;
import com.xxxx.server.service.IMenuService;
import com.xxxx.server.service.IRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-08-17
 */
@RestController
@RequestMapping("/system/basic/")
public class RoleController {

    @Autowired
    private IRoleService roleService;
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IMenuRoleService menuRoleService;

    /**
     * 查询所有角色
     * @return
     */
    @ApiOperation("查询角色列表")
    @GetMapping("/permiss")
    public List<Role> getAllRoles() {
        return roleService.getAllRoles();

    }

    @ApiOperation("添加角色")
    @PostMapping("/permiss/role")
    public RespBean addRole(@RequestBody Role role) {
        return roleService.addRole(role);
    }

    @ApiOperation("删除角色")
    @DeleteMapping("/permiss/role/{id}")
    public RespBean deleteRole(@PathVariable Integer id) {
        return roleService.deleteRole(id);
    }


    @ApiOperation("查询所有菜单")
    @GetMapping("/permiss/menus")
    public List<Menu> getAllMenus(Integer id) {
        return menuService.getAllMenus(id);
    }



    @ApiOperation("根据角色id查询菜单id")
    @GetMapping("/permiss/mid/{rid}")
    public List<Integer> getMidByRid(@PathVariable Integer rid) {

        return menuRoleService.getMidByRid(rid);

    }

    @ApiOperation("更新角色菜单")
    @PutMapping("/permiss")
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        return menuRoleService.updateMenuRole(rid, mids);
    }

}
